package com.itheima.controller;
import com.itheima.dto.PageResult;
import com.itheima.dto.QueryPageBean;
import com.itheima.dto.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkitem")
public class CheckItemController {

    @Autowired
    private CheckItemService checkItemService;

    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    @PostMapping("/findPage")
    public PageResult findAll(@RequestBody QueryPageBean queryPageBean) {

        PageResult page = checkItemService.findPage(queryPageBean);

        return page;
    }

    /**
     * 新增
     * @param checkItem
     * @return
     */
    @PostMapping
    public Result add(@RequestBody CheckItem checkItem){
        checkItemService.addCheckItem(checkItem);

        return Result.success("新增成功");
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable int id){

        checkItemService.deleteById(id);

        return Result.success("删除成功！");
    }

    /**
     * 编辑窗口回显信息
     * @return
     */
    @GetMapping("/{id}")
    public Result getEdit(@PathVariable int id){

        CheckItem checkItem = checkItemService.editById(id);


        return Result.success(checkItem,"操作成功！");
    }

    /**
     * 编辑
     * @param checkItem
     * @return
     */
    @PutMapping
    Result edit (@RequestBody CheckItem checkItem){
        checkItemService.edit(checkItem);
        return Result.success("编辑成功");
    }

    /**
     * 查找全部
     * @return
     */
    @GetMapping("/list")
    Result findAll(){
        List<CheckItem> list = checkItemService.findAll();
        return Result.success(list,"查询成功");
    }

   /* @GetMapping("/{code}")
    public Result getId(@PathVariable String code){
        //checkItemService.getFind(code);


        return Result.success("查询成功！");
    }*/



}
